<template>
  <view>
    <view v-if="sceneType == 1">
      <InformationCollection ref="InformationCollectionRef" />
    </view>
    <view v-if="sceneType == 2"> 邀请页面 </view>
    <view v-if="sceneType == 3"> 需求 </view>
  </view>
</template>

<script setup>
import { checkLogin } from "@/utils/auth.js";
import InformationCollection from "../../components/common/informationCollection.vue";
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
import { ref, watch,onMounted } from "vue";
const sceneType = ref(1); // type:1=暖心房,2=工人加入项目;
const project_id = ref(""); //项目id
const invite_user = ref(""); //invite_user邀请用户,用于注册,
const invite_corp = ref(""); // invite_corp邀请企业,用于注册;

const InformationCollectionRef = ref(null);

onLoad(() => {
  // // 获取sceneType和project_id
  // sceneType.value = uni.getStorageSync("sceneType");
  // project_id.value = uni.getStorageSync("project_id");
  // invite_user.value = uni.getStorageSync("invite_user");
  // invite_corp.value = uni.getStorageSync("invite_corp");
  // // 设置导航栏标题
  // setNavigationBarTitle();
  // console.log('这是已经登录状态111',sceneType.value,project_id.value,invite_user.value,invite_corp.value)

  // 清空storage
  // uni.setStorageSync('sceneType', '')
  // uni.setStorageSync('project_id', '')
});
onShow(() => {
  if (!checkLogin()) {
    console.log('这是未登录状态')
    // 在跳转到登录页时
    return;
  }
 // 获取sceneType和project_id
 sceneType.value = uni.getStorageSync("sceneType");
  project_id.value = uni.getStorageSync("project_id");
  invite_user.value = uni.getStorageSync("invite_user");
  invite_corp.value = uni.getStorageSync("invite_corp");
  // 设置导航栏标题
  setNavigationBarTitle();
  console.log('这是已经登录状态333',sceneType.value,project_id.value,invite_user.value,invite_corp.value)
});
// onMounted(()=>{
//    // 获取sceneType和project_id
//    sceneType.value = uni.getStorageSync("sceneType");
//   project_id.value = uni.getStorageSync("project_id");
//   invite_user.value = uni.getStorageSync("invite_user");
//   invite_corp.value = uni.getStorageSync("invite_corp");
//   // 设置导航栏标题
//   setNavigationBarTitle();
//   console.log('这是已经登录状态222',sceneType.value,project_id.value,invite_user.value,invite_corp.value)
// })
// 设置顶部导航 title
const setNavigationBarTitle = () => {
  let title = "";
  switch (sceneType.value) {
    case "1":
      title = "暖心房信息采集";
      break;
    case "2":
      title = "邀请页面";
      break;
    case "3":
      title = "需求";
      break;
    default:
      title = "";
  }
  uni.setNavigationBarTitle({
    title: title,
  });
};
// onUnload(() => {
// 	// console.log('删除储存的值')
// 	// uni.setStorageSync('sceneType', '');
// 	// uni.setStorageSync('project_id', '');
// 	// uni.setStorageSync('invite_user', '');
// 	// uni.setStorageSync('invite_corp', '');
// });
watch(sceneType, setNavigationBarTitle);
</script>

<style scoped lang="less"></style>
